<template>
    <section>
        <!-- ------------------ 查看患者二维码 ------------------ -->
        <el-dialog class="dialog-frame patient-qr-dialog" title="二维码" :visible.sync="visible" @close="onClose" :close-on-click-modal="false" :close-on-press-escape="false">
            <el-image class="qr__code" :src="info.loginMiniQrcodeurl">
                <div slot="error" class="image-slot">
                    <i class="el-icon-picture-outline"></i>
                </div>
            </el-image>

            <div v-if="!isOnlyready" class="qr__row">
                <span class="row__name">处方：</span>
                <el-button size="mini" type="primary" plain v-for="(c, cIndex) in info.prescriptionList" :key="cIndex" @click="showPdf(c.prescriptionId,4)">
                    {{ c.prescriptionNo }}
                </el-button>
            </div>
        </el-dialog>

        <!-- ------------------ 查看PDF ------------------ -->
        <pdf-dialog ref="pdfDialog" :has-save="false"></pdf-dialog>
    </section>
</template>

<script>
    import pdfDialog from '@/components/chatroom/view-pdf';
    export default {
        props: {
            isOnlyready: {
                type: Boolean,
                default: false
            }
        },
        components: {
            pdfDialog
        },
        data() {
            return {
                visible: false,
                info: {},
            }
        },
        methods: {
            onOpen({ data } = {}) {
                this.info = { ...data };
                this.visible = true;
            },
            onClose() {
                this.visible = false;
                Object.assign(this.$data, this.$options.data.call(this));

                this.$emit('closed')
            },


            /* ------------------ 查看PDF ------------------ */
            showPdf(id, resourceType) { //打开pdf、img
                let params = {
                    id: id, //数据id
                    resource: resourceType, //1=生成住院建议书 2=生成健康指导 3=生成检验检查单 4=生成处方单
                }

                this.$refs.pdfDialog && this.$refs.pdfDialog.onOpen(params);
            },
        }
    }
</script>

<style lang="scss" src="@/style/page/vedio.scss"></style>
<style lang="scss">
    .patient-qr-dialog {
        .qr__row {
            margin: 12px 0;
        }

        .qr__code {
            display: block;
            width: 200px;
            margin: 12px auto;
        }
    }
</style>